package com.zy.openchat.core.model.message;

import android.os.Parcel;
import android.os.Parcelable;

public class SecretChatInfo implements Parcelable {
    public long id;
    public long user_id;
    public SecretChatState state;
    public boolean is_outbound;
    public long ttl;
    public String layer;

    public boolean isClosed(){
        return state==null?false:state.isClosed();
    }

    public boolean isReady(){
        return state==null?false:state.isReady();
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeLong(this.id);
        dest.writeLong(this.user_id);
        dest.writeParcelable(this.state, flags);
        dest.writeByte(this.is_outbound ? (byte) 1 : (byte) 0);
        dest.writeLong(this.ttl);
        dest.writeString(this.layer);
    }

    public void readFromParcel(Parcel source) {
        this.id = source.readLong();
        this.user_id = source.readLong();
        this.state = source.readParcelable(SecretChatState.class.getClassLoader());
        this.is_outbound = source.readByte() != 0;
        this.ttl = source.readLong();
        this.layer = source.readString();
    }

    public SecretChatInfo() {
    }

    protected SecretChatInfo(Parcel in) {
        this.id = in.readLong();
        this.user_id = in.readLong();
        this.state = in.readParcelable(SecretChatState.class.getClassLoader());
        this.is_outbound = in.readByte() != 0;
        this.ttl = in.readLong();
        this.layer = in.readString();
    }

    public static final Creator<SecretChatInfo> CREATOR = new Creator<SecretChatInfo>() {
        @Override
        public SecretChatInfo createFromParcel(Parcel source) {
            return new SecretChatInfo(source);
        }

        @Override
        public SecretChatInfo[] newArray(int size) {
            return new SecretChatInfo[size];
        }
    };
}
